package de.kardass.jannobatch.skiprepeatabort;

import static org.junit.Assert.*;

import de.kardass.jannobatch.ItemWriterAdapter;

public class ItemWriter extends ItemWriterAdapter<WorkflowItem> {
    
    private boolean firstItemReachedWrite = false; 
    private boolean secondItemReachedWrite = false; 
    private boolean thirdItemReachedWrite = false; 

    @Override
    public void write(WorkflowItem item) {
        switch (item.getId()) {
            case 0:
                firstItemReachedWrite = true;
                assertEquals("wrong counter value", 1, item.getCounter()); 
                assertEquals("wrong value repeat counter", 0, item.getRepeatCounter()); 
                assertEquals("wrong value skip item counter", 0, item.getSkipItemCounter()); 
                assertEquals("wrong value skip step counter", 0, item.getSkipStepCounter()); 
                break;
            case 1:
                secondItemReachedWrite = true;
                assertEquals("wrong counter value", 2, item.getCounter()); 
                assertEquals("wrong value repeat counter", 1, item.getRepeatCounter()); 
                assertEquals("wrong value skip item counter", 0, item.getSkipItemCounter()); 
                assertEquals("wrong value skip step counter", 0, item.getSkipStepCounter()); 
                break;
            case 2:
                thirdItemReachedWrite = true;
                assertEquals("wrong counter value", 1, item.getCounter()); 
                assertEquals("wrong value repeat counter", 0, item.getRepeatCounter()); 
                assertEquals("wrong value skip item counter", 0, item.getSkipItemCounter()); 
                assertEquals("wrong value skip step counter", 1, item.getSkipStepCounter()); 
                break;
            default:
                fail("Never come to this position");
                break;
        }
    }

    @Override
    public void onShutDown() {
        assertTrue("'complete workflow test' didn't reach write", firstItemReachedWrite); 
        assertTrue("'repeat 1st step test' didn't reach write", secondItemReachedWrite); 
        assertTrue("'skip 1st step test' didn't reach write", thirdItemReachedWrite); 
    }

    
}
